package com.iecas.xxx.controller;

import com.iecas.xxx.common.api.CommonResult;
import com.iecas.xxx.model.Demo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Redis示例controller
 */
@Api(tags = "Redis示例")
@RestController
public class RedisDemoController {

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation(value = "获取Redis缓存列表")
    @RequestMapping(value = "/cache/listAll", method = RequestMethod.GET)
    public CommonResult<List<Demo>> getList() {
        List<Demo> demoList = (List<Demo>) redisTemplate.opsForValue().get("demoList");
        return CommonResult.success(demoList);
    }
}
